package com.raozg;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * 文件按行读取
 * @Author: raozg
 * @date: 2022/2/17
 */
public class FileReaderTest {
    public static void main(String[] args) {
        BufferedReader bufferedReader=null;
        try {
            bufferedReader = new BufferedReader(new FileReader("src/main/java/com/raozg/text.txt"));
            String reader = bufferedReader.readLine();
            while (reader != null) {
                System.out.println(reader);
                reader = bufferedReader.readLine();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(bufferedReader != null){
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
